<?php $sN = "Content"; ?>
<script type="text/javascript">
    function delete_image(id){
        if(confirm("Are you sure to delete this image ?")){
            $.get('<?php echo $this->Html->url(array('controller'=>'users','action'=>'content_delete_image')) ?>/'+id, function(data){
                if(data=='true'){
                    $('#product-table tr#'+id).fadeOut('slow', function(){
                       $(this).remove(); 
                    });
                }
            });
        }
        return false;
    }
    function play_video(){
        $('#video_play').removeClass("hidden");
        source = $('#video_url').val();//http://www.youtube.com/watch?v=atCfTRMyjGU
        id = source.split("=");
        id_video = id[1];
        html = "<iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/"+id_video+"\" frameborder=\"0\" allowfullscreen></iframe>";
        //$('#video').after('<tr id="play_vi"><td colspan="3">'+html+'</td></tr>');
        $('#video_play div').html(html);
        return false;
    }
    function hide_player(){
        $('#video_play').addClass("hidden");
        $('#video_play div').html('');
        return false;
    }
</script>
<div id="content">
    <div id="page-heading"><h1>Edit Content <?=$this->data['Content']['type']?></h1></div>
    <table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
        <tr>
            <th rowspan="3" class="sized">
                 <?php echo $this->Html->image('../images/shared/side_shadowleft.jpg', array('alt' => '', 'width' => '20', 'height' => '300')); ?>
            </th>
            <th class="topleft"></th>
            <td id="tbl-border-top">&nbsp;</td>
            <th class="topright"></th>
            <th rowspan="3" class="sized">
                <?php echo $this->Html->image('../images/shared/side_shadowright.jpg', array('alt' => '', 'width' => '20', 'height' => '300')); ?>
             </th>
        </tr>
        <tr>
            <td id="tbl-border-left"></td>
            <td>
                <div id="content-table-inner">
                    <table border="0" width="100%" cellpadding="0" cellspacing="0">
                        <tr valign="top">
                            <td>
                                <?php echo $this->Form->create("$sN", array('url'=>array('controller'=>'users','action' => 'content_edit'), 'class' => 'form', 'type' => 'file')); ?>
                                <table border="0" cellpadding="0" cellspacing="0"  id="id-form">
                                <?php
                                    echo $this->Session->flash();
                                    echo $this->Form->input('id');
                                ?>
                                    <tr>
                                        <th valign="top">Title:</th>
                                        <td>
                                            <?php
                                                echo $this->Form->input('title', array(
                                                                    'label'     => false,
                                                                    'div'       => false,
                                                                    'class'     => 'inp-form med')
                                                    );     
                                            ?>      
                                        </td>
                                        <td></td> 
                                    </tr>
                                    <tr>
                                        <th valign="top">Main image:</th>
                                        <td>
                                            <?php
                                                echo $this->Form->input('main_image', array(
                                                        'label'     => false,
                                                        'type'      => 'file',
                                                        'div'       => false,
                                                        'class'     => 'inp-form med')
                                                    ); 
                                            ?>      
                                        </td>
                                        <td>
                                            <?php if($this->data['Content']['main_image']){ 
                                                echo $this->Html->image("contents/thumb/{$this->data['Content']['main_image']}");
                                            } ?>
                                        </td> 
                                    </tr>
                                    <tr id="video">
                                        <th valign="top">Video link :</th>
                                        <td>
                                            <?php
                                                echo $this->Form->input('videos', array(
                                                        'label'     => false,
                                                        'div'       => false,
                                                        'id'        =>'video_url',
                                                        'class'     => 'inp-form med')
                                                    ); 
                                            ?>      
                                        </td>
                                        <td>
                                            <a class="button" href="#" onclick="return play_video()">Check video</a>
                                        </td> 
                                    </tr>
                                    <tr id="video_play" class="hidden">
                                        <td colspan="3">
                                            <div style="display: inline-block"></div>
                                            <a class="button" style="display: inline-block;position: absolute" href="#" onclick="return hide_player()">Hide video</a>
                                        </td>
                                    </tr>
                                    <tr>
                                        <th valign="top">More image: <a class="button" href="<?php echo $this->Html->url(array('action'=>'content_images',$this->data['Content']['id'])) ?>">Image control</a></th>
                                        <td colspan="2">
                                            <table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
                                            <?php 
                                                $alt = 0;
                                                foreach($images as $value): 
                                                    $alt_row = $alt % 2;
                                                    $alt_rows = ($alt_row == 1)? 'alternate-row': '';
                                            ?>
                                                <tr id="<?=$value["ContentImage"]['id']?>" class="<?php echo $alt_rows; ?>">
                                                    <td align="center" >
                                                        <?php echo $this->Html->image("contents/thumb/{$value["ContentImage"]['image']}") ?>
                                                    </td>
                                                    <td width="50" align="center">
                                                    <?php 
                                                        echo $this->Html->link(' ', "#", array('onclick'=>"return delete_image('{$value["ContentImage"]['id']}')",'title' => "Delete", "class" => "icon-2 info-tooltip"));
                                                    ?> 
                                                    </td>
                                                </tr>
                                            <?php
                                                $alt++;
                                                endforeach; 
                                            ?>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <th valign="top">Description:</th>
                                        <td></td>
                                        <td></td> 
                                    </tr>
                                    <tr>
                                        <td colspan="3">
                                            <?php echo $this->Html->script('tiny_mce/tiny_mce'); ?>
                                            <script type="text/javascript">
                                            // O2k7 skin
                                            tinyMCE.init({
                                                    // General options
                                                    mode : "exact",
                                                    elements : "description",
                                                    theme : "advanced",
                                                    skin : "o2k7",
                                                    plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

                                                    // Theme options
                                                    theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
                                                    theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
                                                    theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
                                                    theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
                                                    theme_advanced_toolbar_location : "top",
                                                    theme_advanced_toolbar_align : "left",
                                                    theme_advanced_statusbar_location : "bottom",
                                                    theme_advanced_resizing : true,

                                                    // Example content CSS (should be your site CSS)
                                                    content_css : "/emstraining/css/admin/screen.css",

                                                    // Drop lists for link/image/media/template dialogs
                                                    template_external_list_url : "/emstraining/js/tiny_mce/plugins/template/editor_plugin.js",
                                                    external_link_list_url : "js/link_list.js",
                                                    external_image_list_url : "js/image_list.js",
                                                    media_external_list_url : "/emstraining/js/tiny_mce/plugins/media/editor_plugin.js",

                                                    // Replace values for the template plugin
                                                    template_replace_values : {
                                                            username : "Some User",
                                                            staffid : "991234"
                                                    }
                                            });
                                            </script>
                                            <?php
                                                    echo $this->Form->input('description', array(
                                                            'label'     => false,
                                                            'id'        =>'description',
                                                            'div'       => false,
                                                            'style'     =>'height:500px',
                                                            'class'     => 'inp-form med')
                                                        ); 
                                                ?>
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>&nbsp;</th>
                                        <td valign="top">
                                            <?php echo $this->Form->submit('Save', array('div'=>false,'class' => 'submit-button')); ?>
                                            <?php echo $this->Html->link('Cancel', array('controller' => "users", 'action' => 'content', 'admin' => true), array('class' => 'cancel-button')); ?>
                                        </td>
                                        <td></td>
                                    </tr>
                                </table>
                                <?php echo $this->Form->end();?>    
                            </td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>
                               <?php echo $this->Html->image('../images/shared/blank.gif', array('alt' => 'blank', 'width' => '695', 'height' => '1')); ?>
                            </td>
                            <td></td>
                        </tr>
                    </table>
                    <div class="clear"></div>
                </div>
            </td>
            <td id="tbl-border-right"></td>
        </tr>
        <tr>
            <th class="sized bottomleft"></th>
            <td id="tbl-border-bottom">&nbsp;</td>
            <th class="sized bottomright"></th>
        </tr>
    </table>
    <div class="clear">&nbsp;</div>
</div>